package com.xhwl.logistics.converter;

import com.google.common.base.Strings;
import com.xhwl.common.dto.cent.vehicle.feign.VehiclePayRecordQuery;
import com.xhwl.logistics.bo.input.QueryVehiclePayRecordBO;
import com.xhwl.logistics.dto.query.VehiclePayRecordDTO;
import com.xhwl.logistics.enums.VehicleCardTypeEnum;
import com.xhwl.logistics.util.MathUtil;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Component;

@Component
public class ToQueryVehiclePayRecordBO {

    public QueryVehiclePayRecordBO toQueryVehiclePayRecordBO(VehiclePayRecordDTO vehiclePayRecordDTO) {
        QueryVehiclePayRecordBO queryVehiclePayRecordBO = new QueryVehiclePayRecordBO();

        BeanUtils.copyProperties(vehiclePayRecordDTO, queryVehiclePayRecordBO, "cardType", "minPaidMoney", "maxPaidMoney");
        String cardType = vehiclePayRecordDTO.getCardType();
        if (!Strings.isNullOrEmpty(cardType)) {
            queryVehiclePayRecordBO.setCardType(VehicleCardTypeEnum.toVehicleCardTypeEnum(cardType).getId());
        }

        Integer minPaidMoney = MathUtil.amountDoubletoInteger(vehiclePayRecordDTO.getMinPaidMoney());
        Integer maxPaidMoney = MathUtil.amountDoubletoInteger(vehiclePayRecordDTO.getMaxPaidMoney());
        if (null!=minPaidMoney) {
            queryVehiclePayRecordBO.setMinPaidMoney(minPaidMoney);
        }
        if (null!=maxPaidMoney) {
            queryVehiclePayRecordBO.setMaxPaidMoney(maxPaidMoney);
        }

        return queryVehiclePayRecordBO;
    }

    public QueryVehiclePayRecordBO vehiclePayRecordQuery2QueryVehiclePayRecordBO(VehiclePayRecordQuery vehiclePayRecordQuery) {
        QueryVehiclePayRecordBO queryVehiclePayRecordBO = new QueryVehiclePayRecordBO();

        BeanUtils.copyProperties(vehiclePayRecordQuery, queryVehiclePayRecordBO, "cardType", "minPaidMoney", "maxPaidMoney");
        String cardType = vehiclePayRecordQuery.getCardType();
        if (!Strings.isNullOrEmpty(cardType)) {
            queryVehiclePayRecordBO.setCardType(VehicleCardTypeEnum.toVehicleCardTypeEnum(cardType).getId());
        }

        Integer minPaidMoney = vehiclePayRecordQuery.getMinPaidMoney();
        Integer maxPaidMoney = vehiclePayRecordQuery.getMaxPaidMoney();
        if (null != minPaidMoney) {
            queryVehiclePayRecordBO.setMinPaidMoney(minPaidMoney * 100);
        }
        if (null != maxPaidMoney) {
            queryVehiclePayRecordBO.setMaxPaidMoney(maxPaidMoney * 100);
        }

        return queryVehiclePayRecordBO;
    }
}
